﻿using Iworld.Basis.Model;
using Iworld.Author.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Game.Model
{
    /// <summary>
    /// 牌局的投注信息
    /// </summary>
    public class Betting : RecordingTimeModelBase
    {

        /// <summary>
        /// 赔率
        /// </summary>
        public readonly static Dictionary<PokerColor,double> Odds = new Dictionary<PokerColor,double>(); 

        static Betting()
        {
            Odds.Add(PokerColor.黑桃, 3.8);
            Odds.Add(PokerColor.红桃, 3.8);
            Odds.Add(PokerColor.梅花, 4);
            Odds.Add(PokerColor.方块, 4);
            Odds.Add(PokerColor.王, 20);
        }

        public Betting() {  }

        public Betting(Iworld.Author.Model.Author owner, GameRound gameRound,
            double spade,double heart,double club,double diamond,double king) 
        {
            this.Owner = owner;
            this.GameRound = gameRound;
            this.Spade = spade;
            this.Heart = heart;
            this.Club = club;
            this.Diamond = diamond;
            this.King = king;
        }

        /// <summary>
        /// 投注人
        /// </summary>
        public virtual Iworld.Author.Model.Author Owner { get; set; }

        /// <summary>
        /// 投注局
        /// </summary>
        public virtual GameRound GameRound { get; set; }


        /// <summary>
        /// 黑桃的投注量
        /// </summary>
        public double Spade { set; get; }
        /// <summary>
        /// 红桃的投注量
        /// </summary>
        public double Heart { set; get; }
        /// <summary>
        /// 梅花的投注量
        /// </summary>
        public double Club { set; get; }
        /// <summary>
        /// 方块的投注量
        /// </summary>
        public double Diamond { set; get; }
        /// <summary>
        /// 王的投注量
        /// </summary>
        public double King { set; get; }

        /// <summary>
        /// 当前状态
        /// </summary>
        public BettingStatus Status { get; set; }

        /// <summary>
        /// 中奖分数
        /// </summary>
        public double Bonus { get; set; }

        /// <summary>
        /// 反奖
        /// </summary>
        /// <param name="round"></param>
        public void Pay(GameRound round)
        {
            if(round == null)
            {
                round = GameRound;
            }
            if (!round.IsLottery) return;
            this.Status = BettingStatus.未中奖;
            Dictionary<PokerColor, double> betting = new Dictionary<PokerColor, double>();
            betting.Add(PokerColor.黑桃, Spade);
            betting.Add(PokerColor.红桃, Heart);
            betting.Add(PokerColor.梅花, Club);
            betting.Add(PokerColor.方块, Diamond);
            betting.Add(PokerColor.王, King);
            PokerColor color = round.PokerColor;
            double betWinValue = betting[color];
            if (betWinValue > 0)
            {
               double odds =  Odds[color];
               this.Bonus = betWinValue * odds;
               if(color == PokerColor.王)
               {
                   this.Bonus += (Spade + Heart + Club + Diamond);
               }
               this.Bonus = Math.Round(this.Bonus,0);
               this.Status = BettingStatus.中奖;
            }
 
        }
    }
}
